package com.wap.framework.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class EncryptUtil {
	
	public static String digest(String source) {
		try {
			if (source != null) {
				MessageDigest md = MessageDigest.getInstance("MD5");
				return EncryptUtil.byte2hex(md.digest(source.getBytes()));
			}
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static String byte2hex(byte[] bytes) {
		StringBuffer buffer = new StringBuffer(bytes.length * 2);
		for (int i = 0; i < bytes.length; i++) {
			if (((int) bytes[i] & 0xff) < 0x10) {
				buffer.append("0");
			}
			buffer.append(Long.toString((int) bytes[i] & 0xff, 16));
		}
		return buffer.toString();
	}
	
	 public static void main(String[] args){
		 String passwordEn=EncryptUtil.digest("aa");
		 System.out.println("passwordEn="+passwordEn);
		 
	 }
}
